import React from 'react';
import './index.less';
import {bindAction, bindModel, render} from 'react-division';
import {Button} from 'antd';
import DaAction from './actions/DaAction';
import DaModel from './models/DaModel';
import createModel from 'lib/Modal';
import createForm from 'lib/ConfigForm';
import createTable from 'lib/ConfigTable';

import EditModal from './models/Edit';
import EditAction from './actions/Edit';
import InfoFormModel from './models/InfoForm';
import InfoFormAction from './actions/InfoForm';
import ListModel from './models/List';
import ListAction from './actions/List';

bindAction({
    daPageA: DaAction,
    infoEditA: EditAction,
    infoFormA: InfoFormAction,
    listA: ListAction
});
bindModel({
    daPageM: DaModel,
    infoEditM: EditModal,
    infoFormM: InfoFormModel,
    listM: ListModel
});

const InfoModal = createModel({
    modelName: 'infoEditM',
    actionName: 'infoEditA'
});
const InfoForm = createForm({
    modelName: 'infoFormM',
    actionName: 'infoFormA'
});
const ListTable = createTable({
    modelName: 'listM',
    actionName: 'listA'
});

export default render({
    models: ['daPageM'],
    actions: ['daPageA', 'listA']
})(class extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        const {action} = this.props;

        return (
            <div className="design-action-page">
                <div className="design-action-header">
                    <Button
                        onClick={action.daPageA.showInfoModal}
                    >
                        新建逻辑类
                    </Button>
                </div>
                <InfoModal>
                    <InfoForm />
                </InfoModal>
                <ListTable 
                    operation={[{
                        label: '编辑信息',
                        visible: true,
                        onClick: action.listA.editRow
                    }, {
                        label: '编辑属性',
                        visible: true,
                        onClick: action.listA.editProp
                    }]}
                />
            </div>
        );
    }
})